﻿/********************************************************************************/
// <copyright file="AdminMembershipService.cs" company="Asia E-Business Solutions">
//     Copyright © 2012. All right reserved
// </copyright>
// <history>
//     <change who="Phuoc Le" date="27/12/2012 9:58:03 AM">Created</change>
// </history>
/********************************************************************************/

using System;
using System.Web.Security;

namespace JLL.China.Application.Services.Membership
{
    public class AdminMembershipService : IMembershipService
    {
        private readonly MembershipProvider _provider;

        public AdminMembershipService()
            : this(null)
        {
        }

        public AdminMembershipService(MembershipProvider provider)
        {
            _provider = provider ?? System.Web.Security.Membership.Provider;
        }

        #region IMembershipService Members

        public int MinPasswordLength
        {
            get
            {
                return _provider.MinRequiredPasswordLength;
            }
        }

        public bool ValidateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");

            return _provider.ValidateUser(userName, password);
        }

        public MembershipCreateStatus CreateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");

            MembershipCreateStatus status;
            _provider.CreateUser(userName, password, null, null, null, true, null, out status);
            return status;
        }

        public bool ChangePassword(string userName, string oldPassword, string newPassword)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
